<template>
	<view  style="overflow: scroll;width: 750rpx;display: flex;flex-direction: column;">
		
		<view class="tabb">
			<span :class="door_class_list"  @click="door_class_change()">门店订单</span>
			<span :class="buy_class_list"  @click="buy_class_change()">买单订单</span>
			<span :class="other_class_list"  @click="other_class_change()">其他订单</span>
		</view>
		
		<view v-if="!orderHistoryList.length" style="margin-top: 200rpx;">
			
			<emptyOrder></emptyOrder>
		</view>
		<view style="margin-top: 100rpx;margin-bottom: 100rpx;">
			<view v-if="orderHistoryList.length" v-for="(value,key,index) in total_list" class="list">
				<view style="padding: 20rpx;border-radius: 30rpx;width: 720rpx;background-color: white;display: flex;flex-direction: column;align-items: center;">
					<span >订单号：{{key.slice(1,key.length)}}</span>
					<view v-for="(item,index) in value" style="width: 600rpx;">
						<view style="display: flex;margin-top: 30rpx;">
							<image :src="item.image_name" style="width: 150rpx;height: 220rpx;"></image>
							<view style="height: 220rpx;width: 500rpx;display: flex;justify-content: space-between;">
								<view style="display: flex;flex-direction: column;height: 220rpx;justify-content: space-around;">
									<span style="color: black;font-size: 35rpx;font-weight: bold;">{{item.name}}</span>
									<span style="font-size: 30rpx;color: darkgray">{{item.detail}}</span>
									<span style="font-size: 30rpx;color: green;">×{{item.num}}</span>
								</view>
								<span style="color: green;font-size: 35rpx;font-weight: bold;margin-top: 20rpx;">￥{{item.price}}</span>
							</view>
						</view>
					</view>
				</view>
				
					
			</view>
		</view>
		
		
	</view>
</template>

<script>
	import emptyOrder from "../emptyOrder/emptyOrder.vue"
	export default {
		data() {
			return {
				orderHistoryList:[],
				total_list:{},
				door_class_list:[
					"checked",
					"tab"
				],
				buy_class_list:[
					
					"tab"
				],
				other_class_list:[
					
					"tab"
				],
			}
		},
		methods: {
			door_class_change(){
				this.door_class_list=["checked","tab"];
				this.buy_class_list=["tab"];
				this.other_class_list=["tab"];
			},
			buy_class_change(){
				this.buy_class_list=["checked","tab"];
				this.door_class_list=["tab"];
				this.other_class_list=["tab"];
			},
			other_class_change(){
				this.other_class_list=["checked","tab"];
				this.buy_class_list=["tab"];
				this.door_class_list=["tab"];
			},
		},
		components:{
			emptyOrder
		},
		onShow() {
			
		},
		created() {
			var t=this
			uni.request({
				url:"http://localhost:3000/getHistoryOrders",
				success(data) {
					//console.log(data.data)
					
					t.orderHistoryList=data.data
					let single_list=[]
					
					for(let i=0;i<t.orderHistoryList.length;i++){
						
						if(single_list.indexOf(t.orderHistoryList[i].order_id)==-1){
							single_list.push(t.orderHistoryList[i].order_id)
						}
					}
					single_list=single_list.reverse()
					for(let i=0;i<single_list.length;i++){
						let items=[]
						for(let ii=0;ii<t.orderHistoryList.length;ii++){
							if(t.orderHistoryList[ii].order_id==single_list[i]){
								items.push(t.orderHistoryList[ii])
							}
						}
						console.log("",items);
						t.$set(t.total_list,"l"+single_list[i],items)
						
					}
					
					console.log("",t.total_list);
				}
			})
		},
		
	}
</script>

<style scoped>
	
.tab{
		display: block;
		width:172rpx;
		height: 80rpx;
		font-size: 40rpx;
		color:grey;
		text-align: center;
		
		font-weight: 400;
	}
	.checked{
		border-bottom: 5rpx solid green;
		color: green;
	}
	.tabb{
		width: 747rpx;
		height:104rpx;
		border-width: 1rpx;
		border-color: #ededed;
		border-style: solid;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		align-items: flex-end;
		background-color: white;
		position: fixed;
		top: 105rpx;
		margin-bottom: 500rpx;
	}
	.list{
		
		display: flex;
		width: 720rpx;
		align-items: center;
		flex-direction: column;
		
		
		padding: 30rpx;
	}
	/* .list:first-of-type{
		display: flex;
		width: 720rpx;
		align-items: center;
		flex-direction: column;
		margin-top: 200rpx;
		
		padding: 30rpx;
	} */
</style>
